Page({

  data: {
    show1: false,
    show2: false,
    show3: false,
    flag:false,
    columns: ['汉语言文学', '新闻学', '网络与新媒体'],
    columns1: [],
    columns2: [],
    title: '',
    sections: '',
    introduce: '',
    teacher: '',
    videoUrl: '',
    imgUrl:'/image/add_image.png'
  },

  onLoad(options) {

  },

  showPopup(e) {
    const id = parseInt(e.currentTarget.dataset.id)
    this.setData({
      ['show' + id]: true
    })
  },

  onClose(e) {
    const id = parseInt(e.currentTarget.dataset.id)
    this.setData({
      ['show' + id]: false
    })
  },

  onChange(event) {
    const id = parseInt(event.currentTarget.dataset.id);
    const {
      value
    } = event.detail;
    const dataMap = {
      1: 'zhuanye',
      2: 'fangxiang',
      3: 'teacher',
    };
    this.setData({
      [dataMap[id]]: value
    });
  },

  onConfirm(e) {
    const id = parseInt(e.currentTarget.dataset.id);
    const { zhuanye = this.data.columns[0], fangxiang, teacher } = this.data;
  
    if (id === 1) {
      this.setColumns(zhuanye);
    }
  
    const dataMap = {
      1: { fangxiang: '', teacher: '', zhuanye, show1: false },
      2: { fangxiang: fangxiang || this.data.columns1[0], show2: false },
      3: { teacher: teacher || this.data.columns2[0], show3: false }
    };
  
    this.setData({
      ...dataMap[id]
    });
  },
  


  setColumns(zhuanye) {
    const columns1 = {
      '汉语言文学': ['中国古代文学史'],
      '新闻学': ['传播方向', '广告方向'],
      '网络与新媒体': ['前端方向', '数据方向', '产品经理方向', '新媒体方向']
    }
    const columns2 = {
      '汉语言文学': ['ceshi'],
      '新闻学': ['ceshi', 'ceshi'],
      '网络与新媒体': ['ceshi', 'ceshi', 'ceshi', 'ceshi']
    }
    this.setData({
      columns1: columns1[zhuanye] || [],
      columns2: columns2[zhuanye] || []
    })
  },

  CourseSections(e) {
    const sections = e.detail
    this.setData({
      sections
    })
  },
  CourseName(e) {
    const title = e.detail
    this.setData({
      title
    })
  },
  CourseIntroduce(e) {
    const introduce = e.detail
    this.setData({
      introduce
    })
  },
  ChooseImage(e){
    wx.chooseImage({
      count: 1,
      success:res=> {
        const tempFilePaths = res.tempFilePaths
        this.setData({
          imgUrl : tempFilePaths,
          flag:!this.data.flag
        })
      }
    })
  },
  chooseVideo: function () {
    var _this = this;
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      success: function (res) {
        console.log(res)
        _this.setData({
          videoUrl: res.tempFilePath
        })
        // _this.uploadVideo(res.tempFilePath)
      }
    })
  },


  // uploadVideo: function (filePath) {
  //   var _this = this;
  //   wx.showLoading({
  //     title: '上传中',
  //   })
  //   wx.uploadFile({
  //     url: 'your upload url',
  //     filePath: filePath,
  //     name: 'file',
  //     header: {
  //       'content-type': 'multipart/form-data'
  //     },
  //     success: function (res) {
  //       wx.hideLoading()
  //       console.log(res)
  //     }
  //   })
  // }

})